package stu.khy.action;

import javax.annotation.Resource;

import stu.khy.comm.Constants;
import stu.khy.entity.Employee;
import stu.khy.service.EmployeeService;


public class LoginEmployeeAction extends BaseAction {
	private String userName;
	private String password;
	private String random;
	@Resource
	private EmployeeService employeeService;
	
	private Employee manager;
	
	
	public String login() {
	Object sessionRandom=this.getSession().get("random");
	Employee employee=employeeService.loginEmp(userName, password);
	
	
	if(employee!=null) {
		if(random == null || !random.equals(sessionRandom)) {
//			this.addActionError(this.getText("errors.codeerror"));
			
			manager= employeeService.getManager(employee);
			//把当前员工存储在当前会话里面
			this.getSession().put(Constants.AUTH_EMPLOYEE, employee);
			this.getSession().put(Constants.AUTH_EMPLOYEE_MANAGER, manager);
			this.getSession().put(Constants.EMPLOYEE_POSITION, employee.getSysPosition().getNameCn());
		
			return INPUT;
		}else {	
				
			return SUCCESS;
		}
	}	
		return INPUT;
	}
	
	
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}


	public String getRandom() {
		return random;
	}


	public void setRandom(String random) {
		this.random = random;
	}
}
